import { createRouter, createWebHistory } from 'vue-router';
import NProgress from 'nprogress'; // progress bar
import 'nprogress/nprogress.css';
import baseComponent from '@/common/router/base-component';
import { appRoutes } from './routes';
import { REDIRECT_MAIN, NOT_FOUND_ROUTE } from './routes/base';
import createRouteGuard from './guard';

NProgress.configure({ showSpinner: false }); // NProgress Configuration

const constantRoutes = [
  {
    path: '/',
    redirect: 'login',
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index.vue'),
    meta: {
      requiresAuth: false,
    },
  },
  {
    path: '/sso-login',
    name: 'ssoLogin',
    component: () => import('@/views/login/sso-login/index.vue'),
    meta: {
      requiresAuth: false,
    },
  },
  {
    path: '/token-login',
    name: 'tokenLogin',
    component: () => import('@/views/login/token-login/index.vue'),
    meta: {
      requiresAuth: false,
    },
  },
  {
    path: '/ticket-login',
    name: 'ticketLogin',
    component: () => import('@/views/login/ticket-login/index.vue'),
    meta: {
      requiresAuth: false,
    },
  },
  {
    path: '/root-menu',
    name: 'rootMenu',
    component: () => import('@/views/root-menu/index.vue'),
    meta: {
      requiresAuth: true,
    },
  },
  {
    path: '/buff',
    name: 'Buff',
    component: () => import('@/views/redirect/buff-redirect/index.vue'),
    meta: {
      requiresAuth: true,
      hideInMenu: true,
    },
  },
  baseComponent,
  ...appRoutes,
  REDIRECT_MAIN,
  NOT_FOUND_ROUTE,
];

const router = createRouter({
  history: createWebHistory('/purchase/'),
  routes: constantRoutes,
  scrollBehavior() {
    return { top: 0 };
  },
});

createRouteGuard(router);

export default router;
